#pragma once

#include "base_define.h"

namespace xBase
{
    class BASE_API CxLock
    {
    public:
        CxLock();
        ~CxLock();

        VOID Acquire();
        VOID Release();

        BOOL Try();

    private:
        CRITICAL_SECTION m_cs;

    protected:
        CxLock(const CxLock& other);
        CxLock& operator = (const CxLock& other);
    };

    class BASE_API CxAutoLock
    {
    public:
        explicit CxAutoLock(CxLock& lock)
            : m_Lock(lock)
        {
            m_Lock.Acquire();
        }

        ~ CxAutoLock()
        {
            m_Lock.Release();
        }

    private:
        CxLock & m_Lock;

    private:
        CxAutoLock(const CxAutoLock& other);
        CxAutoLock & operator == (const CxAutoLock & right);
    };
}